package org.zxn.study.factory.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.zxn.study.constants.UserLoginConstants;
import org.zxn.study.strategy.UserGranter;
import org.zxn.study.strategy.impl.AccountGranter;
import org.zxn.study.strategy.impl.SmsGranter;
import org.zxn.study.strategy.impl.WeChatGranter;

/**
 * @ClassName UserLoginFactory
 * @Description: 用户登录工厂类
 * @Author zxn
 * @Date 2025/7/10 11:33
 **/
@Component
public class UserLoginFactory {
    @Autowired
    private AccountGranter accountGranter;

    @Autowired
    private SmsGranter smsGranter;

    @Autowired
    private WeChatGranter weChatGranter;

    private static Map<String, UserGranter> granterPool = new ConcurrentHashMap<>();

    @PostConstruct
    public void init(){
        granterPool.put(UserLoginConstants.ACCOUNT_TYPE,accountGranter);
        granterPool.put(UserLoginConstants.PHONE_TYPE,smsGranter);
        granterPool.put(UserLoginConstants.WEB_CHAT_TYPE,weChatGranter);
    }

    /**
     * 对外提供获取具体策略
     */
    public UserGranter getGranter(String grantType){
        return granterPool.get(grantType);
    }
}
